﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using IterationLife.System.Models;
using Util.Domains;

namespace IterationLife.UserProfiles.Models {
    /// <summary>
    /// 用户资料
    /// </summary>
    [Description( "用户资料" )]
    public partial class UserProfile : AggregateRoot<UserProfile> {
        /// <summary>
        /// 初始化用户资料
        /// </summary>
        public UserProfile() : this( Guid.Empty ) {
        }

        /// <summary>
        /// 初始化用户资料
        /// </summary>
        /// <param name="id">用户资料标识</param>
        public UserProfile( Guid id ) : base( id ) {
            UserBodyInfos = new List<UserBodyInfo>();
            UserRelatives = new List<UserRelative>();
        }

        /// <summary>
        /// 用户编号
        /// </summary>
        public Guid? UserId { get; set; }
        /// <summary>
        /// 姓名
        /// </summary>
        [StringLength( 20, ErrorMessage = "姓名输入过长，不能超过20位" )]
        public string Name { get; set; }
        /// <summary>
        /// 昵称
        /// </summary>
        [StringLength( 20, ErrorMessage = "昵称输入过长，不能超过20位" )]
        public string NickName { get; set; }
        /// <summary>
        /// 头像
        /// </summary>
        [StringLength( 250, ErrorMessage = "头像输入过长，不能超过250位" )]
        public string Avatar { get; set; }
        /// <summary>
        /// 性别
        /// </summary>
        public int? Gender { get; set; }
        /// <summary>
        /// 出生日期
        /// </summary>
        public DateTime? Birthday { get; set; }
        /// <summary>
        /// 身份证号
        /// </summary>
        [StringLength( 20, ErrorMessage = "身份证号输入过长，不能超过20位" )]
        public string IdentityNumber { get; set; }
        /// <summary>
        /// 所在地
        /// </summary>
        [StringLength( 100, ErrorMessage = "所在地输入过长，不能超过100位" )]
        public string Location { get; set; }
        /// <summary>
        /// 所在地编码
        /// </summary>
        [StringLength( 20, ErrorMessage = "所在地编码输入过长，不能超过20位" )]
        public string LocationCode { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreationTime { get; set; }
        
        /// <summary>
        /// 用户身体信息列表
        /// </summary>
        public virtual ICollection<UserBodyInfo> UserBodyInfos { get; set; }
        
        /// <summary>
        /// 用户
        /// </summary>
        public virtual User User { get; set; }
        
        /// <summary>
        /// 用户亲属列表
        /// </summary>
        public virtual ICollection<UserRelative> UserRelatives { get; set; }
        
        /// <summary>
        /// 添加描述
        /// </summary>
        protected override void AddDescriptions() {
            AddDescription( "用户资料编号", Id );
            AddDescription( "用户编号", UserId );
            AddDescription( "姓名", Name );
            AddDescription( "昵称", NickName );
            AddDescription( "头像", Avatar );
            AddDescription( "性别", Gender );
            AddDescription( "出生日期", Birthday );
            AddDescription( "身份证号", IdentityNumber );
            AddDescription( "所在地", Location );
            AddDescription( "所在地编码", LocationCode );
            AddDescription( "创建时间", CreationTime );
        }
        
        /// <summary>
        /// 添加变更列表
        /// </summary>
        protected override void AddChanges( UserProfile newEntity ) {
            AddChange( "Id", "用户资料编号", Id, newEntity.Id );            
            AddChange( "UserId", "用户编号", UserId, newEntity.UserId );
            AddChange( "Name", "姓名", Name, newEntity.Name );
            AddChange( "NickName", "昵称", NickName, newEntity.NickName );
            AddChange( "Avatar", "头像", Avatar, newEntity.Avatar );
            AddChange( "Gender", "性别", Gender, newEntity.Gender );
            AddChange( "Birthday", "出生日期", Birthday, newEntity.Birthday );
            AddChange( "IdentityNumber", "身份证号", IdentityNumber, newEntity.IdentityNumber );
            AddChange( "Location", "所在地", Location, newEntity.Location );
            AddChange( "LocationCode", "所在地编码", LocationCode, newEntity.LocationCode );
            AddChange( "CreationTime", "创建时间", CreationTime, newEntity.CreationTime );
        }
    }
}